package mysql

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"time"
)

func OpenMySql(ip, port string) (*xorm.Engine, error) {
	db, err := xorm.NewEngine("mysql", "root:password@tcp("+ip+":"+port+")/mysql?charset=utf8")
	//impl, err := sql.Open("mysql", "root:password@tcp("+ip+":"+port+")/mysql?charset=utf8&parseTime=True")
	db.ShowSQL(true)
	//impl.Logger().SetLevel(core.LOG_ERR)
	if err != nil {
		return nil, err
	}
	return db, err
}

func OpenMySql2(ip, port string) (*xorm.Engine, error) {
	db, err := xorm.NewEngine("mysql", "root:password@tcp("+ip+":"+port+")/gluenet?charset=utf8")
	//impl, err := sql.Open("mysql", "root:password@tcp("+ip+":"+port+")/mysql?charset=utf8&parseTime=True")
	db.ShowSQL(false)
	db.TZLocation = time.Local
	//impl.Logger().SetLevel(core.LOG_ERR)
	if err != nil {
		return nil, err
	}
	return db, err
}
